﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FAFramework
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        private Button AddBottomMenuButton(Grid grid, string caption, RoutedEventHandler eventHandler)
        {
            Button button = new Button();
            button.Content = caption;
            button.Margin = new Thickness(2, 2, 2, 2);
            button.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            button.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            button.Width = double.NaN;
            button.Height = double.NaN;
            ColumnDefinition col = AddBottomMenuColumn(grid);
            grid.Children.Add(button);
            Grid.SetColumn(button, grid.ColumnDefinitions.Count - 1);

            button.Click += eventHandler;
            return button;
        }

        private Button AddBottomMenuButton(Grid grid, string caption, Page page)
        {
            RoutedEventHandler action =
                delegate(object sender, RoutedEventArgs e)
                {
                    ShowPage(page);
                };

            Button button = AddBottomMenuButton(grid, caption, action);
            return button;
        }

        private ColumnDefinition AddBottomMenuColumn(Grid grid, int width = 0)
        {
            ColumnDefinition col = new ColumnDefinition();
            if (width > 0)
                col.Width = new GridLength(width);
            grid.ColumnDefinitions.Add(col);
            return col;
        }

        private void ShowPage(Page page)
        {
            frameMainView.Content = page;
        }

        public MainWindow()
        {
            InitializeComponent();

            Manager.PartManager partManager = new Manager.PartManager();

            partManager.LoadFromFile(@".\config\PartList.xml");

            MessageBox.Show(partManager.aPart.Description);
            frameMainView.NavigationUIVisibility = NavigationUIVisibility.Hidden;

            frameDateTime.Content = new Forms.Main.PageDateTime();
            AddBottomMenuButton(GridBottomMenu, "Main", new Forms.Main.PageMain());
            AddBottomMenuButton(GridBottomMenu, "Manual", new Forms.Manual.PageManual());
            AddBottomMenuColumn(GridBottomMenu, 100);
            AddBottomMenuButton(GridBottomMenu, "Exit", delegate(object sender, RoutedEventArgs e) { Close();  });
        }
    }
}
